package config

import (
	"encoding/json"
	"io/ioutil"
	"log"
	"os"
	"path"
)

type Orz struct {
	Extname   []string        `json:"extname"`
	Thumbnail ThumbnailConfig `json:"thumbnail"`
	Limits    LimitsConfig    `json:"limits"`
}

type ThumbnailConfig struct {
	Height uint16 `json:"height" valid:"required"`
	Width  uint16 `json:"width" valid:"required"`
}

type LimitsConfig struct {
	Files    int   `json:"files" valid:"required"`
	FileSize int64 `json:"fileSize" valid:"required"`
}

var (
	_cfg map[string]Orz
)

func init() {
	file, _ := os.Getwd()
	str, err := ioutil.ReadFile(path.Join(file, "config.json"))
	if nil != err {
		log.Fatal(err)
	}

	if err := json.Unmarshal(str, &_cfg); nil != err {
		log.Fatal(err)
	}

	log.Println("loadCfg")
}

// type Status struct {
// 	Code int
// 	Err  error
// 	Data interface{}
// }

func Get(key *string) (Orz, bool) {
	orz, ok := _cfg[*key]
	return orz, ok
}
